package com.dc.free.config;

import com.dc.free.controller.IndexController;
import com.dc.free.db.model._MappingKit;
import com.dc.free.handler.GlobalHandler;
import com.dc.free.util.DruidPluginUtil;
import com.jfinal.config.Constants;
import com.jfinal.config.Handlers;
import com.jfinal.config.Interceptors;
import com.jfinal.config.JFinalConfig;
import com.jfinal.config.Plugins;
import com.jfinal.config.Routes;
import com.jfinal.core.Const;
import com.jfinal.core.JFinal;
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
import com.jfinal.plugin.druid.DruidPlugin;
import com.jfinal.template.Engine;

public class Config extends JFinalConfig{

	@Override
	public void configConstant(Constants me) {
		loadPropertyFile("config.properties");
		me.setDevMode(true);
		me.setBaseDownloadPath(Const.DEFAULT_BASE_UPLOAD_PATH);
	}

	@Override
	public void configRoute(Routes me) {
		me.setBaseViewPath("view");
		me.add("/", IndexController.class);
		me.add(new CharityRoutes());
		me.add(new AdminRoutes());
	}

	@Override
	public void configEngine(Engine me) {
	}

	@Override
	public void configPlugin(Plugins me) {
		// 配置C3p0数据库连接池插件
		DruidPlugin dp = DruidPluginUtil.create();
        me.add(dp);	
		// 配置ActiveRecord插件
		ActiveRecordPlugin arp = new ActiveRecordPlugin(dp);
        arp.setDialect(DruidPluginUtil.getDialect());  //指定 Dialect
        _MappingKit.mapping(arp);
        me.add(arp);
	}

	@Override
	public void configInterceptor(Interceptors me) {
	}

	@Override
	public void configHandler(Handlers me) {
		me.add(new GlobalHandler());
	}
	
	@Override
	public void afterJFinalStart() {
		super.afterJFinalStart();
	}

	@Override
	public void beforeJFinalStop() {
		super.beforeJFinalStop();
	}

	public static void main(String[] args) {
		JFinal.start("src/main/webapp", 8088, "/free", 5);
	}
}
